package com.vanke.devops.dal.util;

import com.google.common.base.Function;
import com.google.common.collect.Iterators;

public class StringUtils {
    public static String captureName(String name) {
        char[] cs = name.toCharArray();
        if (cs[0] >= 'a' && cs[0] <= 'z') {
            cs[0] -= 32;
        }
        return String.valueOf(cs);
    }


    public static boolean isEmpty(String str) {
        return str== null ? true : "".equals(str.trim());
    }


    public static <T> String join(Iterable<T> elements, String sep, final String leftEleStr, final String rightEleStr) {
        return org.apache.commons.lang3.StringUtils.join(Iterators.transform(elements.iterator(), new Function<T, String>() {
            @Override
            public String apply(T from) {
                return leftEleStr + from + rightEleStr;
            }
        }), sep);
    }

    public static <T> String join(Iterable<T> elements, String sep, final String eleStr) {
        return join(elements, sep, eleStr, eleStr);
    }

    public static <T> String join(Iterable<T> elements,String sep){
        return join(elements, sep, "", "");
    }

    public static String startsWith(String str, String sep) {
        if (str == null) {
            return null;
        }
        return str.startsWith(sep) ? str : sep + str;
    }

    public static String[] split(String str, String sep) {
        if(isEmpty(str)){
            return new String[0];
        }
        return str.split(sep);
    }
}

